package com.leyou.item.controller;

import com.leyou.item.service.CategoryService;
import com.ly.plus.entity.Category;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import sun.util.resources.ga.LocaleNames_ga;

import javax.management.MXBean;
import java.util.List;

/**
 * 类别表控制层
 */
@RestController
@MapperScan("com.leyou.item.mapper")
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     * 查询所有分类
     * @param pid
     * @return
     */
    @GetMapping("/of/parent")
    public ResponseEntity<List<Category>> findCategoryByPid(@RequestParam("pid") Long pid){
        List<Category> list= categoryService.findCategoryByPid(pid);
        //return ResponseEntity.ok(list);
        return ResponseEntity.status(HttpStatus.OK).body(list);//上下一样效果

    }

    /**
     * 根据id集查询分类
     * @param ids
     * @return
     */
    @GetMapping("/list")
    public ResponseEntity<List<Category>>findCategorysByIds(@RequestParam("ids")List<Long>ids){
       List<Category>categories= categoryService.findCategorysByIds(ids);
       return ResponseEntity.ok(categories);
    }
}
